﻿using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web;
using System.Collections.Specialized;
using System.Collections;
using System;

/// <summary>
/// Descripción breve de Helpers
/// </summary>
namespace IUAP
{
    public static class Helpers
    {
        private static string[] _ciudades = new string[] { 
         "Andahuasi", "Ambar", "Barranca", "Cajatambo", "Carquín","Canta", 
         "Checras", "Huacho", "Hualmay", "Huaura", "Huaral", 
         "Lima", "Pativilca", "Paramonga","Santa María", "Vegueta"};
        public static StringCollection GetCiudad()
        {
            StringCollection ciudad = new StringCollection();
            ciudad.AddRange(_ciudades);
            return ciudad;
        }
        public static SortedList GetCiudad(bool insertEmpty)
        {
            SortedList ciudad = new SortedList();
            if (insertEmpty)
                ciudad.Add("", "Por favor, seleccione una...");
            foreach (String country in _ciudades)
                ciudad.Add(country, country);
            return ciudad;
        }
        public static void SetInputControlsHighlight(Control container, string className, bool onlyTextBoxes)
        {
            foreach (Control ctl in container.Controls)
            {
                if ((onlyTextBoxes && ctl is TextBox) || ctl is TextBox ||
                ctl is DropDownList || ctl is ListBox || ctl is CheckBox ||
                ctl is RadioButton || ctl is RadioButtonList || ctl is CheckBoxList)
                {
                    WebControl wctl = ctl as WebControl;
                    string stylos = wctl.CssClass;

                    wctl.Attributes.Add("onfocus", string.Format(
                       "this.className = '{0} {1}';", className, stylos));
                    wctl.Attributes.Add("onblur", string.Format(
                        "this.className = '{0}';", stylos));
                }
                else
                {
                    if (ctl.Controls.Count > 0)
                        SetInputControlsHighlight(ctl, className, onlyTextBoxes);
                }
            }
        }
        public static string ConvertToHtml(string content)
        {
            content = HttpUtility.HtmlEncode(content);
            content = content.Replace("  ", "&nbsp;&nbsp;").Replace(
               "\t", "&nbsp;&nbsp;&nbsp;").Replace("\n", "<br>");
            return content;
        }
    }
}